package com.frxuexi.park2210.notice

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import androidx.paging.cachedIn
import com.frxuexi.lib_base.entity.NoticeBeanItem
import com.frxuexi.lib_base.mvvm.BaseViewModel
import com.frxuexi.lib_base.net.ApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

@HiltViewModel
class NoticeViewModel @Inject constructor(val apiService: ApiService):BaseViewModel() {
    /*var noticeSuc =MutableLiveData<String>()

    fun getNotice(map: Map<String,Int>){
        httpRequest({apiService.getNotices(mapToBody(map))},noticeSuc::postValue)
    }*/
    var addnoticeSuc =MutableLiveData<String>()

    fun getNotice():Flow<PagingData<NoticeBeanItem>>{
        return Pager(config= PagingConfig(10),pagingSourceFactory = {
            NewsDataSource(apiService)
        }).flow.cachedIn(viewModelScope)
    }

    fun addNotice(map: Map<String,Any>){
        httpRequest({apiService.addNotice(mapToBody(map))},addnoticeSuc::postValue)
    }

}